package com.ycz.demo.util;

import org.csource.fastdfs.*;

/**
 * @author yancz
 * @ClassName FastDfsUtil
 * @description: fastdfs工具类
 * @date 2024-01-23 11:23:16
 * @version: 1.0
 */
public class FastDfsUtil {

    /*
     * @author yancz
     * @description 获取StorageClient1对象
     * @date 2024/1/23 17:03
     * @Param
     * @return StorageClient1
     **/
    public static StorageClient1 initStorageClient1() {
        try {
            // 加载配置
            ClientGlobal.initByProperties("fastdfs-client.properties");
            // 定义client对象
            TrackerClient trackerClient = new TrackerClient();
            // 连接Server
            TrackerServer trackerServer = trackerClient.getConnection();
            if(trackerServer == null) {
                System.out.println("tracker server is null！");
            }
            // 获取Storage对象
            StorageServer storageServer = trackerClient.getStoreStorage(trackerServer);
            if(storageServer == null) {
                System.out.println("storage server is null！");
            }
            return new StorageClient1(trackerServer,storageServer);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
